package com.xk.timerapp.data;

import androidx.room.Room;

import com.xk.timerapp.App;

public class AlarmClockDatabaseManager {
    private static AlarmClockDatabase instance;
    private static final String DATABASE_NAME = "alarm_clock_database";

    // 私有构造函数，防止外部使用 new 关键字创建对象
    private AlarmClockDatabaseManager() {
    }

    // 静态内部类，用于实现单例模式中的懒汉式初始化
    private static class DatabaseHolder {
        private static final AlarmClockDatabase INSTANCE = Room.databaseBuilder(
                        App.instance.getApplicationContext(), // 假设 MyApp 是你的 Application 类
                        AlarmClockDatabase.class, DATABASE_NAME)
                .build();
    }

    // 获取单例数据库对象的方法
    public static AlarmClockDatabase getInstance() {
        if (instance == null) {
            synchronized (AlarmClockDatabaseManager.class) {
                if (instance == null) {
                    instance = DatabaseHolder.INSTANCE;
                }
            }
        }
        return instance;
    }
}